<?php
#####################################################
# RWCARDS - Joomla E-Cards Componment!
# Copyright (C) 2004/2005 by Ralf Weber
# Company    : LoadBrain
# Homepage   : www.weberr.de
# Version    : 2.1.0
# Date       : 23/11/2005
# License    : Released under GPL
######################################################

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

if ( !defined('_RWCARDS_LANG_INCLUDED') ) 
{
  	if ( file_exists($mosConfig_absolute_path . "/components/com_rwcards/language/" . $mosConfig_lang . ".php") )
	{
    	include_once($mosConfig_absolute_path . "/components/com_rwcards/language/" . $mosConfig_lang . ".php");
  	}
	else 
	{
    	include_once($mosConfig_absolute_path . "/components/com_rwcards/language/english.php");
	}
}

class rwcards_cards_html
{

/**
* Displays Cards
*
* Lists all the cards
*/	
	function RWCardsListCards( &$rows, &$pageNav, $search, $option, $selectedCategory, $categoryList ) 
	{
    global $mosConfig_live_site, $my;
	$categoryName = "";
?>
<br />
<script language="JavaScript">
function changeCategory()
{
	document.adminForm.task.value= 'cards';
	document.adminForm.action = 'index2.php?option=com_rwcards&task=cards';
	document.adminForm.submit();
}
</script>
<div align="center" class="centermain">
<table border="0" cellspacing="0" cellpadding="5">
<tr>
	<td><img src="./components/com_rwcards/images/admin_add_over.jpg" alt="<?php echo _ADMIN_RWCARDS_ADDCARD_TITLE; ?>" width="49" height="49" border="0"></td>
	<th><?php echo _ADMIN_RWCARDS_ADDCARD_TITLE; ?></td>
	</tr>
</table>
<br />
	<form action="" method="post" name="adminForm">
	<table cellpadding="4" cellspacing="0" border="0" width="100%">
		<tr> 
      <td width="100%"><?php echo _ADMIN_RWCARDS_CATEGORY . "<strong>" . $categoryName . "</strong>"; ?><?php echo $categoryList; ?></td>
			<td nowrap="nowrap"><?php echo _ADMIN_RWCARDS_DISPLAY; ?> #</td>
			<td> <?php echo $pageNav->writeLimitBox(); ?> </td>
			<td><?php echo _ADMIN_RWCARDS_SEARCH; ?>:</td>
			<td><input type="text" name="search" value="<?php echo $search;?>" class="inputbox" onChange="document.adminForm.submit();" /></td>
		</tr>
	</table>
	<table cellpadding="4" cellspacing="0" border="10" width="100%" class="adminlist">
		<tr>
			<th width="20" nowrap="nowrap">#</th>
			<th width="20" class="title" nowrap="nowrap"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);" /></th>
			<th class="title" nowrap="nowrap"><?php echo _ADMIN_RWCARDS_MANAGE_CARDS_AUTHOR; ?></th>
			<th class="title" nowrap="nowrap"><?php echo _ADMIN_RWCARDS_MANAGE_CARDS_EMAIL; ?></th>
			<th class="title" nowrap="nowrap"><?php echo _ADMIN_RWCARDS_MANAGE_CARDS_PICTURE; ?></th>
			<th class="title" nowrap="nowrap"><?php echo _ADMIN_RWCARDS_MANAGE_CARDS_DESCRIPTION; ?></th>
			<th width="50" class="title" nowrap="nowrap"><?php echo _ADMIN_RWCARDS_PUBLISHED; ?></th>
			<th colspan="2" nowrap="nowrap"><?php echo _ADMIN_RWCARDS_REORDER; ?></th>
		</tr>
<?php
		$k = 0;
		for ($i=0, $n=count($rows); $i < $n; $i++) 
		{
			$row = $rows[$i];

			$img = $row->published ? 'tick.png' : 'publish_x.png';
			$task = $row->published ? 'unpublish_card' : 'publish_card';
			$title = $row->published ? _ADMIN_RWCARDS_CATEGORY_PUBLISHED : _ADMIN_RWCARDS_CATEGORY_UNPUBLISHED;
      // same like mosCommonHTML::CheckedOutProcessing( $row, $i );
      	if ( $row->checked_out ) 
		{
			  $checked = mosCommonHTML::checkedOut( $row );
  		} 
		else 
		{
  			$checked = mosHTML::idBox( $i, $row->id, ($row->checked_out && $row->checked_out != $my->id ), 'pid' );
  		}
      	$link = 'index2.php?option=com_rwcards&hidemainmenu=1&task=edit_card&pid[]='.$row->id;
?>
		<tr class="<?php echo "row$k"; ?>"> 
			<td><?php echo $i+1+$pageNav->limitstart; ?></td>
		  	<td align="center"><?php echo $checked; ?></td>
			<td><?php 
      if ( $row->checked_out && ( $row->checked_out != $my->id ) ) 
	  {
        echo $row->autor;
      }
      else 
	  {
      ?>
        <a href="<?php echo $link; ?>" title="<?php echo _ADMIN_RWCARDS_CARD_EDIT; ?>"><?php echo $row->autor; ?></a>
      <?php
      }
      ?></td>
	  	<td><?php echo $row->email; ?></td>
		<td><?php echo $row->picture; ?></td>
		<td><?php echo nl2br($row->description); ?></td>

		  <td align="center"><a href="javascript: void(0);" onClick="return listItemTask('cb<?php echo $i;?>','<?php echo $task;?>')"><img src="images/<?php echo $img;?>" width="12" height="12" border="0" alt="" title="<?php echo $title; ?>" /></a></td>
      <td align="center">
<?php		if ($i > 0 || ($i+$pageNav->limitstart > 0))
			{ ?>
	        <a href="javascript: void(0);" onClick="return listItemTask('cb<?php echo $i;?>','orderup_cards')">
	        <img src="images/uparrow.png" width="12" height="12" border="0" title="<?php echo _ADMIN_RWCARDS_MOVE_UP; ?>">
	        </a>
        <?php
			}
		 ?>
      </td>
      <td align="center">
		<?php	
		if ($i < $n-1 || $i+$pageNav->limitstart < $pageNav->total-1) 
		{ ?>
	        <a href="javascript: void(0);" onClick="return listItemTask('cb<?php echo $i;?>','orderdown_cards')">
	        <img src="images/downarrow.png" width="12" height="12" border="0" title="<?php echo _ADMIN_RWCARDS_MOVE_DOWN; ?>">
	        </a>
        <?php	
		} 
		?>
      </td>
		</tr>
    <?php
		 $k = 1 - $k;
	}
	?>
    <tr> 
      <th align="center" colspan="10"> <?php echo $pageNav->writePagesLinks(); ?></th>
    </tr>
    <tr> 
      <td align="center" colspan="10"> <?php echo $pageNav->writePagesCounter(); ?></td>
    </tr>
  </table>
  <input type="hidden" name="option" value="<?php echo $option; ?>" />
  <input type="hidden" name="task" value="cards" />
  <input type="hidden" name="boxchecked" value="0" />
  <input type="hidden" name="hidemainmenu" value="0" />
</form>
<?php
  }

/**
*	New / Edit Cards
*/
function RWCardsEditCard( &$row, $option, $imageFiles, $categoryList, $olist ) 
{
		mosMakeHtmlSafe( $row, ENT_QUOTES, 'description' );
?>
	<script language="javascript" type="text/javascript">
		
		function submitbutton(pressbutton) {
			var form = document.adminForm;
			if (pressbutton == 'cancel') {
				submitform( pressbutton );
				return;
			}

			// do field validation
			if (form.autor.value == "")
			{
				alert( "<?php echo _ADMIN_RWCARDS_PROVIDE_NAME; ?>" );
			}
			else 
			{
				submitform( pressbutton );
			}
		}

		function changeImagePreview()
		{
				if (document.adminForm.picture.options[document.adminForm.picture.selectedIndex].selected == true)
			{
				document.images['imageFile'].src = '../images/stories/cards/' + document.adminForm.picture.options[document.adminForm.picture.selectedIndex].value;
			}
			else
			{
				document.images['imageFile'].src = 'images/blank.png';
			}
		}
		</script>
<table border="0" cellspacing="0" cellpadding="5">
<tr>
	<td><img src="./components/com_rwcards/images/admin_add_over.jpg" title="<?php echo _ADMIN_RWCARDS_ADDCARD_TITLE; ?>" width="49" height="49" border="0"></td>
	<th><?php echo ( $row->id ? _ADMIN_RWCARDS_CARD_EDIT : _ADMIN_RWCARDS_NEW_CARD );?></td>
	</tr>
</table>
<br />
	<form action="index2.php" method="POST" name="adminForm">
	<table cellpadding="4" cellspacing="1" border="0" width="100%" class="adminform">
		<tr> 
			<td width="15%" align="right"><?php echo _ADMIN_RWCARDS_MANAGE_CARDS_AUTHOR; ?>:</td>
			<td width="85%" colspan="2"><input class="inputbox" type="text" name="autor" size="50" maxlength="100" value="<?php echo $row->autor; ?>" /></td>
		<tr> 
		<tr> 
			<td width="15%" align="right"><?php echo _ADMIN_RWCARDS_MANAGE_CARDS_PICTURE; ?></td>
			<td width="85%" colspan="2"><?php echo $imageFiles; ?></td>
		<tr> 
		<tr> 
			<td width="15%" align="right"><?php echo _ADMIN_RWCARDS_CATEGORY; ?></td>
			<td width="85%" colspan="2"><?php echo $categoryList; ?></td>
		<tr> 
		<tr> 
			<td width="15%" align="right"><?php echo _ADMIN_RWCARDS_MANAGE_CARDS_EMAIL; ?></td>
			<td width="85%" colspan="2"><input class="inputbox" type="text" name="email" size="50" maxlength="100" value="<?php echo $row->email; ?>" /></td>
		<tr> 
		<tr> 
			<td width="15%" align="right" valign="top"><?php echo _ADMIN_RWCARDS_MANAGE_CARDS_DESCRIPTION; ?></td>
			<td width="85%" colspan="2"><textarea cols="25" rows="3" name="description" id="description" class="inputbox"><?php echo $row->description; ?></textarea></td>
		<tr> 
<!-- 		<tr> 
			<td width="15%" align="right"><?php echo $row->published; ?><?php echo _ADMIN_RWCARDS_CATEGORY_PUBLISHED; ?></td>
			<td width="85%" colspan="2"><input type="checkbox" name="published" value="" <?php echo ($row->published) == "1" ? "checked" : ""; ?> /></td>
		<tr>  -->
		<tr> 
			<td width="15%" align="right" valign="top"><?php echo _ADMIN_RWCARDS_NEW_CARD_PREVIEW_PICTURE; ?></td>
			<td width="85%" colspan="2">
			<?php
			if ($row->picture != "")
			{
				echo "<img name='imageFile' src='../images/stories/cards/" . $row->picture  . "' border='0'></td>";
			}
			else
			{
			?>		
			<?php
				echo "<img name='imageFile' src='../images/stories/cards/' alt='Preview' border='0'></td>";
			}
			if ($row->picture == "")
			{
			?>
			<script language="javascript" type="text/javascript">
		document.images['imageFile'].src =  '../images/stories/cards/' + document.adminForm.picture.options[document.adminForm.picture.selectedIndex].value;

			if (document.adminForm.category_id.length == 0)
			{
				alert( "<?php echo _ADMIN_RWCARDS_ADDCARD_NO_CATEGORIES_DEFINED_YET; ?>" );
				goBack = true;
				if (goBack)
				{
					document.location.href = "index2.php?option=com_rwcards&task=main";
				}
			}
		</script>	
				<?php
			}
			?>
		<tr>
		<tr>
      <td valign="top" align="right"><?php echo _ADMIN_RWCARDS_ORDERING ?>:</td>
      <td> <?php echo $olist; ?> </td>
    </tr>
		<tr> 
			<td colspan="2">&nbsp;</td>
		</tr>
	</table>
	<input type="hidden" name="option" value="<?php echo $option; ?>" />
	<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
	<input type="hidden" name="task" value="" />
	</form>
<?php
	}

}